package IpaTest;

import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * description： <br>
 * createTime: 2017/12/119:16 <br>
 *
 * @author zzh
 */
public class IosDemo {
    private WebDriver driver;

    @BeforeClass
    public void setUp() throws Exception {

    }

    @Test
    public void testApp() throws MalformedURLException {
        // set up appium
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(MobileCapabilityType.UDID, "F676C6B5-C471-4800-B116-9331A4B467A2");
//capabilities.setCapability(MobileCapabilityType.ACCEPT_SSL_CERTS,true);
        capabilities.setCapability(MobileCapabilityType.PLATFORM, "Mac");
        capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "11.2");
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iphone X");
        capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "ios");
        capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");

        //如果app已经安装在测试机上了，则传BundleID，否则传app安装文件的路径
//        capabilities.setCapability("bundleId", "com.zhihu.ios");
        capabilities.setCapability(MobileCapabilityType.APP, "/Users/zhihuizhou/Documents/TestSwift.app");
//capabilities.setCapability(MobileCapabilityType.APP,"com.iqiyi.reliao");
        driver = new RemoteWebDriver(new URL("http://192.168.24.133:4723/wd/hub"), capabilities);

        System.out.println(driver);
        driver.close();
    }

    @Test
    public void testSofari() throws MalformedURLException {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(MobileCapabilityType.UDID, "F676C6B5-C471-4800-B116-9331A4B467A2");
        capabilities.setCapability(MobileCapabilityType.PLATFORM, "Mac");
        capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
        capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "11.2");
        capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Safari");
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone X");
        driver = new RemoteWebDriver(new URL("http://192.168.24.133:4723/wd/hub"), capabilities);
        driver.get("https://baidu.com/");
        System.out.println(driver);
        driver.close();
    }

    @AfterClass(alwaysRun = true)
    public void tearDown() throws Exception {
        driver.quit();
    }
}
